package com.paishen.peiniwan.database.util;


import com.paishen.peiniwan.frame.http.entity.AuthInfo;
import com.paishen.peiniwan.frame.http.entity.Coupon;
import com.paishen.peiniwan.frame.http.entity.Gift;
import com.paishen.peiniwan.frame.http.entity.Photo;
import com.paishen.peiniwan.frame.http.entity.User;
import com.paishen.peiniwan.frame.http.entity.UserMiscInfo;

/**
 * Created by peng on 2015/12/19.
 */
public class ModelConverter {

    public static final com.paishen.peiniwan.database.User mergeOrReplace(com.paishen.peiniwan.database.User target, User user) {
        if (target == null) {
            target = new com.paishen.peiniwan.database.User();
            target.setId(user.id);
        }
        target.setPhone(user.phone);

        target.setEasemob_username(user.easemob_username);
        target.setEasemob_password(user.easemob_password);
        target.setHead_img_url(user.head_img_url);
        target.setHead_img_url_max(user.head_img_url_max);
        target.setNickname(user.nickname);
        target.setGender(user.sex == User.MALE);
        target.setIntro(user.intro);
        target.setTags(user.tags);
        target.setIs_verified(user.is_verified);
        target.setGood_rate(user.good_rate);
        target.setConcern(user.collectCount);
        target.setFans(user.fansCount);
        target.setAmount(user.goldAmount);
        target.setGift1(user.giftCount1 != null ? user.giftCount1 : 0);
        target.setGift5(user.giftCount2 != null ? user.giftCount2 : 0);
        target.setGift10(user.giftCount3 != null ? user.giftCount3 : 0);

        target.setSalary(user.salary);
        target.setHeight(user.height);
        target.setWeight(user.weight);
        target.setAge(user.age);
        target.setDegree(user.degree);
        target.setConstellation(user.constellation);
        target.setProfession(user.profession);
        target.setCity(user.city);

        return target;
    }

    public static final com.paishen.peiniwan.database.Photo mergeOrReplace(com.paishen.peiniwan.database.Photo target, Photo photo, long fkey_userid) {
        if (target == null) {
            target = new com.paishen.peiniwan.database.Photo();
            target.setId(photo.id);
            target.setUserId(fkey_userid);
        }
        target.setPhoto_url(photo.photo_url);
        target.setCreated_date(photo.created_date);
        return target;
    }

    public static final com.paishen.peiniwan.database.Coupon mergeOrReplace(com.paishen.peiniwan.database.Coupon target, Coupon coupon, long fkey_userid) {
        if (target == null) {
            target = new com.paishen.peiniwan.database.Coupon();
            target.setId(coupon.id);
            target.setUserId(fkey_userid);
        }
        target.setCode(coupon.code);
        target.setAmount(coupon.amount);
        target.setIs_valid(coupon.is_valid);
        target.setValid_from(coupon.valid_from);
        target.setValid_to(coupon.valid_to);
        return target;
    }

    public static final com.paishen.peiniwan.database.AuthInfo mergeOrReplace(com.paishen.peiniwan.database.AuthInfo target, AuthInfo authInfo, long fkey_userid) {
        if (target == null) {
            target = new com.paishen.peiniwan.database.AuthInfo();
            target.setUserId(fkey_userid);
            target.setId(authInfo.id);
        }
        target.setReal_photo(authInfo.real_photo);
        target.setCreated_date(authInfo.created_date);
        target.setStatus(authInfo.status);
        target.setNote(authInfo.note);
        return target;
    }

    public static final com.paishen.peiniwan.database.Gift mergeOrReplace(com.paishen.peiniwan.database.Gift target, Gift gift) {
        if (target == null) {
            target = new com.paishen.peiniwan.database.Gift();
            target.setId(gift.id);
        }
        target.setTitle(gift.title);
        target.setPrice(gift.price);
        target.setImage(gift.image);
        return target;
    }
}
